package net.huashitong.synthetical.jobOversee.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.JqGrid;
import com.sirdc.modules.core.web.model.Message;
import net.huashitong.synthetical.jobOversee.Service.DutyUnitService;
import net.huashitong.synthetical.jobOversee.entity.DutyUnit;
import net.huashitong.synthetical.jobOversee.filter.DutyUnitFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/duty/unit")
public class DutyUnitCtrl extends JsonBaseController {

    @Autowired
    private DutyUnitService service;

    @Override
    protected String getView(String s) {
        return "/modules/sys/duty/"+s;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String initPage() {
        return getView("query");
    }
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public JqGrid query(@ModelAttribute DutyUnitFilter filter) {

      List<DutyUnit> lists =  service.getUnitInfo(filter);

        return coverJqGrid(filter, lists);
    }

    @RequestMapping("/filter")
    public String filter(@ModelAttribute DutyUnitFilter filter, Model model) {
        return getView("filter");
    }


    @RequestMapping(value="/create", method=RequestMethod.GET)
    public String showAddView(Model model, @ModelAttribute DutyUnitFilter filter) {

        model.addAttribute("dutyunit",filter);
        return getView("form");
    }

    @ResponseBody
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Message create(@ModelAttribute DutyUnitFilter fileter) {

        service.saveGroup(fileter);
        return coverMessage("200");
    }

}
